using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


    public partial class StudentPages_ViewGrades : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Define data objects
                SqlConnection conn;
                SqlCommand comm;
                SqlDataReader reader;

                string query = @"SELECT
                                        Course.course_Name, Course.room_Num, 
                                        Course.credits, 
                                        Grade.num_Score, 
                                        Grade.letter_Grade, 
                                        Instructor.first_Name, 
                                        Instructor.last_Name
                                FROM            
                                        Course INNER JOIN
                                        Instructor ON Course.instructor_ID = Instructor.instructor_ID INNER JOIN
                                        Roster ON Course.course_ID = Roster.course_ID INNER JOIN
                                        Student ON Roster.student_ID = Student.student_ID CROSS JOIN Grade;";

                // Read the connection string from Web.config
                string connectionString = ConfigurationManager.ConnectionStrings["Capstone"].ConnectionString;

                // Initialize connection
                conn = new SqlConnection(connectionString);

                // Create command
                comm = new SqlCommand(query, conn);

                // Enclose database code in Try-Catch-Finally
                try
                {
                    // Open the connection
                    conn.Open();

                    // Execute the command
                    reader = comm.ExecuteReader();

                    // Fill the grid with data
                    courseDetails.DataSource = reader;
                    //                grid.DataKeyNames = new string[] { "course_ID" };
                    courseDetails.DataBind();

                    // Close the reader
                    reader.Close();
                }
                finally
                {
                    comm = null;
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn = null;
                }
            }
        }
    }
